'''
车辆管理相关页面测试
'''

from Lib.base.page_object.enterprise.enterprise_manage import EnterpriseManager
from selenium.webdriver.common.by import By
import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestEnterprise.enterprise = EnterpriseManager(login)
    TestEnterprise.assert_class = AssertClass(login)


@allure.feature('执法智库安全生产企业页面测试')
class TestEnterprise:

    @allure.title("新建企业")
    def test_01_create_enterprise(self, login):
        with allure.step('为测试部门进行排序'):
            self.enterprise.department_sort()
            # 设置断言
            assert_arg = (By.XPATH, '//p[text()="排序成功"]')
            self.assert_class.make_assert_by_text(args=assert_arg, assert_data='排序成功', context='编辑部门')
        with allure.step('新建部门'):
            self.enterprise.create_enterprise()
            # 设置断言
            assert_args = (By.XPATH, '//p[contains(text(), "新建成功")]')
            self.assert_class.make_assert_by_text(args=assert_args, assert_data='新建成功', context='新建企业')

    @allure.title("查看企业列表")
    def test_02_enterprise_list(self, login):
        with allure.step('根据风险等级进行筛选'):
            self.enterprise.enterprise_list_by_risk_grade()
            # 设置断言
            assert_args = (By.XPATH, '//p[text()="中风险"]')
            self.assert_class.make_assert_by_elements_text(args=assert_args, assert_data='中风险')
        with allure.step('根据规模进行筛选'):
            self.enterprise.enterprise_list_by_scale()
            # 设置断言
            assert_args = (By.XPATH, '//div[text()="大型"]')
            self.assert_class.make_assert_by_elements_text(args=assert_args, assert_data='大型')
        with allure.step('根据部门进行筛选'):
            self.enterprise.enterprise_list_by_department()
            # 设置断言
            assert_args = (By.XPATH, '//pre[text()="流程测试部门"]')
            self.assert_class.make_assert_by_elements_text(args=assert_args, assert_data='流程测试部门')

    @allure.title("搜索企业")
    def test_03_enterprise_search(self, login):
        with allure.step('搜索错误的值'):
            self.enterprise.enterprise_search_error()
            # 设置断言
            assert_args = (By.XPATH, '//p[contains(text(), "暂无数据")]')
            self.assert_class.make_assert_by_elements_text(args=assert_args, assert_data='暂无数据')
        with allure.step('精确搜索和模糊搜索'):
            self.enterprise.enterprise_search()
            # 设置断言
            assert_args = (By.XPATH, '//pre[text()="UI新建单位"]')
            self.assert_class.make_assert_by_elements_text(args=assert_args, assert_data='UI新建单位')

    @allure.title("查看和编辑企业")
    def test_04_enterprise_detail_and_update(self, login):
        self.enterprise.enterprise_detail_and_update()
        # 设置断言
        assert_args = (By.XPATH, '//p[contains(text(), "编辑成功")]')
        self.assert_class.make_assert_by_elements_text(args=assert_args, assert_data='编辑成功')

    @allure.title("删除企业")
    def test_05_enterprise_delete(self, login):
        self.enterprise.enterprise_delete()
        # 设置断言
        assert_args = (By.XPATH, '//p[contains(text(), "删除成功")]')
        self.assert_class.make_assert_by_elements_text(args=assert_args, assert_data='删除成功')


if __name__ == '__main__':
    pytest.main(
        ['-v', '-s', '--reruns=2', '--reruns-delay=1', './enterprise_test.py::TestEnterprise'])
    # pytest.main(['-v', './car_test.py', '--alluredir', '../result', '--clean-alluredir'])
    # os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    # os.system('allure generate  ../result -o ../report/ --clean')
